<template>
	<view>
		<!-- <view class="px-3 py-2 position-fixed top-0 wid100 box-b heade bg-white flex align-center" style="z-index: 9999;box-shadow: 0px 3px 6px 1px rgba(0,0,0,0.06);">
			<picker :range="cityList" range-key="name" @change="cityPicker">
				<view class="flex align-center" style="margin-right: 30rpx;" >
					<u-icon name="map" color="#6E6E6E" size="15"></u-icon>
					<view style="color: #4D4D4D;font-size: 28rpx;padding: 0 4rpx;">{{choiceData.name}}</view>
					<image src="../../static/index/down-icon.png" style="width: 18rpx;height: 18rpx;"></image>
				</view>
			</picker>
			<u-search :clearabled="false" placeholder="输入学校/公寓搜索" :showAction="false" v-model="requestData.keyword"
				@blur="changeInput">
			</u-search>
		</view>
		<view class="" :style="{height:search_height+'px'}"></view> -->
		<view class="community-box" v-for="(item,index) in dataList" :key='index' style="margin-bottom: 20rpx;">
			<view style="display: flex;align-items: center;padding-top: 30rpx;">
				<image :src="item.avatar" mode=""
					style="width: 80rpx;height: 80rpx;border-radius: 50%;" @tap="toUser(item)"></image>
				<view style="padding-left: 20rpx;">
					<view>
						<text style="color: #262626;font-size: 28rpx;">{{item.realname}}</text>
						<text style="color: #A7A7A7;font-size: 22rpx;padding-left: 26rpx;">{{item.major}}</text>
					</view>
					<view style="display: flex;padding-top: 10rpx;">
						<view class="label">{{item.label}}</view>
					</view>
				</view>
			</view>
			<view class="remarks">{{item.desc}}</view>
			<view class="condition" v-if="item.gender_require == 0">男女不限 拼{{item.group_person}}人</view>
			<view class="condition" v-if="item.gender_require == 1">限男生 拼{{item.group_person}}人</view>
			<view class="condition" v-if="item.gender_require == 2">限女生 拼{{item.group_person}}人</view>
			<view class="building" v-if="item.is_booking == 1">
				<view class="flex align-center" style="padding: 20rpx 0;border-bottom: 1px solid #E5E5E5;">
					<image src="../../static/index/das-icon.png" style="width: 32rpx;height: 32rpx;"></image>
					<view style="flex: 1;color: #202020;font-size: 28rpx;padding-left: 18rpx;">{{item.apartment_title}}</view>
					<image src="../../static/index/zu210-2x.png" style="width: 24rpx;height: 24rpx;"></image>
				</view>
				<view class="flex" style="padding: 26rpx 0;">
					<image :src="item.room.thumb" style="width: 144rpx;height: 144rpx;border-radius: 8px;">
					</image>
					<view style="padding-left: 20rpx;">
						<view class="text-one" style="color: #202020;font-size: 28rpx;width: 400rpx;">{{item.room.title}}</view>
						<view style="color: #ABABAB;font-size: 24rpx;padding: 10rpx 0 20rpx 0;">{{item.room.size}}㎡ | {{item.room.toilet}} |
							{{item.room.bed}}
						</view>
						<view class="flex align-end">
							<text class="font-20 fw5" style="color: #C40E0E;">£</text>
							<text class="font-28 fw5"
								style="color: #C40E0E;margin-left: 6rpx;margin-right: 6rpx;">{{item.room.price}}</text>
							<text class="font-20 fw4 cl-88">/周</text>
						</view>
					</view>
				</view>
			</view>
			<view class="apartment" v-else>
				<view style="color: #202020;font-weight: bold;font-size: 28rpx;padding-top: 20rpx;">意向公寓</view>
				<view class="apartment-box" v-for="(apartment,apartmentIndex) in item.want_apartment" :key="apartmentIndex"  @tap="jump({url:'/pages/apartmentDetail/apartmentDetail?id='+apartment.id})">
					<view class="flex" style="padding: 20rpx 0;border-bottom: 1px solid #EFEFEF;">
						<image :src="apartment.thumb"
							style="width: 166rpx;height: 106rpx;border-radius: 4px;"></image>
						<view style="padding-left: 20rpx;">
							<view class="text-one" style="color: #141414;font-size: 24rpx;font-weight: bold;line-height: 24rpx;width: 400rpx;">{{apartment.title}}</view>
							<view class="flex align-center" style="padding: 6rpx 0 15rpx 0;width: 400rpx;">
								<u-icon name="map" color="#6E6E6E" size="11"></u-icon>
								<text class="text-one" style="color: #ABABAB;font-size: 20rpx;padding-left: 6rpx;">{{apartment.address}}</text>
							</view>
							<view class="flex align-end">
								<text class="font-20 fw5" style="color: #C40E0E;">£</text>
								<text class="font-28 fw5"
									style="color: #C40E0E;margin-left: 6rpx;margin-right: 6rpx;">{{apartment.price}}</text>
								<text class="font-20 fw4 cl-88">起 /周</text>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="flex justify-between align-center py-3">
				<view style="color: #A1A1A1;font-size: 28rpx;">发布时间：{{item.createtime_text}}</view>
				<view class="button" @tap="join(item)">参与拼房</view>
			</view>
		</view>
		<view style="height: 300rpx;"></view>
		<view class="fixed-button">
			<view class="button-box flex align-center justify-center">
				<view class="flex align-center" @tap="jump({url:'/pages/index/release'})">
					<image src="../../static/index/fb.png" mode="" style="width: 36rpx;height: 36rpx;"></image>
					<view class="size">发起拼房</view>
				</view>
				<view style="height: 26px;opacity: 0.23;border-left: 1px solid #FFFFFF;margin: 0 60rpx;"></view>
				<button open-type="contact" hover-class="none">
					<view  class="flex align-center">
						<image src="../../static/index/add.png" mode="" style="width: 26rpx;height: 26rpx;"></image>
						<view class="size">加入新生群</view>
					</view>
				</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				search_height: 0,
				requestData:{
					page:1,
					pagesize:10,
					city_id:0,
					keyword:'',
					id:'',//拼房主id
					apartment_id:'',//公寓id
				},
				dataList:[],//数据列表
				moreList:[],//更多
				cityList:[],//城市列表
				choiceData:{id:0,name:'城市'},//城市数据
			}
		},
		onLoad(option) {
			console.log(option)
			if(option.id){
				this.requestData.apartment_id = option.id
			}
			const query = uni.createSelectorQuery().in(this)
			// query.select('.heade').boundingClientRect(data => {
			// 	this.search_height = data.height
			// }).exec()
			this.getData()
			//城市列表
		    this.$H.post(this.$api.get_city_list,{},{token:false}).then(res=>{
				this.cityList = res.data
				// this.choiceData = res.data[0]
				// this.choiceData = res.data[0]
			})	
		},
		onReachBottom() {
			if(this.moreList.length){
				this.requestData.page++
				this.getData()
			}else{
			    console.log('没有数据了')
			}
			
		},
		methods:{
			//用户详情
			toUser(item){
				uni.navigateTo({
					url:`/pages/index/communityUser?id=${item.id}`
				})
			},
			//参加拼房
			join(item){
			    uni.navigateTo({
			    	url:`/pages/index/participate?id=${item.id}`
			    })
			},
			//搜索
			changeInput(){
				this.requestData.page = 1
				this.dataList = []
				this.getData()
			},
			//城市选择
			cityPicker(e){
				console.log(e)
				this.choiceData = this.cityList[e.detail.value]
				this.requestData.city_id = this.cityList[e.detail.value].id
				this.requestData.page = 1
				this.dataList = []
				this.getData()
			},
			//列表数据
			getData(){
				this.$H.post(this.$api.community_list,{...this.requestData},{token:true}).then(res=>{
					this.moreList = res.data.list
					this.dataList = [...this.dataList,...this.moreList]
				})
			}
		}
	}
</script>

<style lang="scss">
	button::after{
	 	border: none;
		
	}
	button{
		background-color: #FFB24B;
		padding-left:0;
		padding-right: 0;
		line-height: 1;
		margin: 0;
	}
	page {
		background: #F3F3F3;
	}

	.community-box {
		padding: 0 30rpx;
		background-color: #fff;

		.label {
			padding: 10rpx;
			font-size: 20rpx;
			font-weight: 400;
			color: #E99320;
			background: #FFECD2;
			border-radius: 10px 4px 9px 5px;
		}

		.remarks {
			padding-top: 36rpx;
			font-size: 28rpx;
			font-weight: 400;
			color: #262626
		}

		.condition {
			padding: 18rpx 0;
			font-size: 30rpx;
			font-weight: 400;
			color: #A1A1A1;
		}

		.building {
			padding: 0 20rpx;
			background: #F9F9F9;
			border-radius: 8px 8px 8px 8px;
		}

		.apartment {
			padding: 0 20rpx;
			background: #F9F9F9;
			border-radius: 8px 8px 8px 8px;
		}

		.apartment-box:last-child {
			border: none;
		}

		.button {
			padding: 20rpx 40rpx;
			font-size: 24rpx;
			font-weight: 400;
			color: #FFFFFF;
			background: #FFB24B;
			border-radius: 34px 34px 34px 34px;
		}
	}

	.fixed-button {
		position: fixed;
		bottom: 70rpx;
		left: 70rpx;
		right: 70rpx;

		.button-box {
			width: 100%;
			height: 84rpx;
			background-color: #FFB24B;
			border-radius: 100px 0 100px 100px;

			.size {
				padding-left: 8rpx;
				font-size: 28rpx;
				font-weight: 400;
				color: #FFFFFF;
			}
		}
	}
</style>
